package com.kylin.core.marketing.query.handler;

import com.kylin.dal.entity.marketing.MarketingBoardEntry;
import com.kylin.dal.entity.marketing.MarketingCampaignEntry;
import com.kylin.domain.commodity.vo.CommodityVO;
import com.kylin.domain.marketing.vo.MarketingCampaignVO;
import com.kylin.domain.marketing.vo.MarketingCommodityVO;
import com.kylin.marketing.api.dto.resp.MarketingBoardRespDTO;
import com.kylin.marketing.api.dto.resp.MarketingCampaignRespDTO;
import com.kylin.shared.utils.MappingTools;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * 营销对象转换接口
 * @author Damon S.
 * @version v1.0.1
 * @date 2020年12月20日 13:29
 */
@Mapper(componentModel = "spring", uses = MappingTools.class)
public interface MarketingTranslator {

    MarketingCommodityVO toMarketingCommodityVO(MarketingBoardEntry entry);

    MarketingCampaignVO toCampaignVO(MarketingCampaignEntry entry);

    MarketingCampaignRespDTO toCampaignRespDTO(MarketingCampaignVO vo);

    @Mapping(source = "price", target = "gPrice")
    @Mapping(source = "comparePrice", target = "cPrice")
    MarketingBoardRespDTO toMarketingBoardRespDTO(MarketingCommodityVO vo);

    @Mapping(source = "price", target = "gPrice")
    MarketingBoardRespDTO toMarketingBoardRespDTO(CommodityVO vo);

    @Mapping(source = "price", target = "gPrice")
    @Mapping(source = "comparePrice", target = "cPrice")
    MarketingBoardRespDTO toMarketingBoardRespDTO(MarketingBoardEntry entry);

    default List<MarketingCampaignVO> toCampaignVO(List<MarketingCampaignEntry> entries) {
        return Optional.ofNullable(entries)
                .orElse(Collections.emptyList())
                .stream()
                .map(this::toCampaignVO)
                .collect(Collectors.toList());
    }

    default List<MarketingBoardRespDTO> toMarketingBoardRespDTO(List<MarketingBoardEntry> entries) {
        return Optional.ofNullable(entries)
                .orElse(Collections.emptyList())
                .stream()
                .map(this::toMarketingBoardRespDTO)
                .collect(Collectors.toList());
    }
}
